package demo;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author ：黄淼淳
 * @date ：2021/12/18 17:30
 * @description：多线程自增类
 */
public class CyclicBarrierDemo {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(8, () -> {
            System.out.println("=====开始开会=====");
        });
        for (int i = 0; i < 8; i++) {
            final int x = i;
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"来了");
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i+1)).start();
        }
    }
}
